package ru.voronoy.thefifteen.listeners;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Map;

import ru.voronoy.thefifteen.entity.Bone;
import ru.voronoy.thefifteen.gameplay.Game;
import ru.voronoy.thefifteen.gameplay.Solution;
import ru.voronoy.thefifteen.gui.MainWindow;

public class BonesKeyListener implements KeyListener {

	private Map<String, Bone> bones;

	public BonesKeyListener(Map<String, Bone> bones) {
		this.bones = bones;
	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
			Game.getInstance().PressRightArrowButton(bones);
		}
		if (e.getKeyCode() == KeyEvent.VK_LEFT) {
			Game.getInstance().PressLeftArrowButton(bones);
		}
		if (e.getKeyCode() == KeyEvent.VK_DOWN) {
			Game.getInstance().PressDownArrowButton(bones);
		}
		if (e.getKeyCode() == KeyEvent.VK_UP) {
			Game.getInstance().PressUpArrowButton(bones);
		}

		if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
			Solution.Hint(bones);
		}

		if (Game.getInstance().isStarted()) {
			if (Game.getInstance().IsOver(bones)) {
				Game.getInstance().Stop();
				MainWindow.FinishFrame(MainWindow.getTimerLabelText());
			}
		}

	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

}
